import Taro from '@tarojs/taro';

export const getToken = () => {
  return Taro.getStorageSync('token');
};

export const setToken = (token: string) => {
  Taro.setStorageSync('token', token);
};

export const removeToken = () => {
  Taro.removeStorageSync('token');
};

export const checkAuth = (cb: Function) => {
  const token = getToken();
  if (token) {
    cb && cb();
  } else {
    Taro.navigateTo({
      url: '/pages/login/index',
    });
  }
};
